// 引入Vue
import Vue from 'vue'
// 引入App
import App from './App.vue'
import router from './router'
// 引入elemetn-ui组件库
import ElementUI from 'element-ui';
// 引入element-ui全部css
import 'element-ui/lib/theme-chalk/index.css';

import Cookie from 'js-cookie'
import store from './store'
import FilePond from './utils/filepond';

import VXETable from 'vxe-table';
import 'vxe-table/lib/index.css';
Vue.use(VXETable);

import * as echarts from 'echarts'
Vue.prototype.$echarts = echarts;

// 引入动画
import WOW from 'wowjs'
import 'wowjs/css/libs/animate.css'
Vue.prototype.$wow = WOW

// 关闭Vue的生产提示
Vue.config.productionTip = false
// 使用element
Vue.use(ElementUI)

// 添加全局前置守卫
router.beforeEach((to, from, next) => {
  // 判断token存不存在
  const token = Cookie.get('token');
  // token不存在,说明当前用户时未登录,应该跳转至登录页
  if (!token && to.path !== '/welcome' && to.path !== '/') {
    next({ path: '/' });
  } else if (token && (to.path === '/welcome' || to.path === '/')) { // token存在,说明用户登录,此时跳转至首页
    next({ path: '/main/' });
  } else {
    next();
  }
})

new Vue({
  FilePond,
  router,
  store,
  render: h => h(App),
  created() {
    // 初始化路由配置
    this.$store.commit('initRouter');
  }
}).$mount('#app')
